<template>
  <div>
    <div align="left">我的位置&gt;&gt;科技项目申报&gt;修改本帐户密码</div>
  <div id="container">
    <div id="content2">
      <table width="100%" height="41" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td width="15" height="18" align="left" valign="top">
            <div align="left"></div>
          </td>
          <td width="385" align="left" valign="bottom" class="12">&nbsp;</td>
        </tr>
        <tr>
          <td height="4" colspan="2" align="left" valign="bottom"></td>
        </tr>
        <tr>
          <td height="15" align="left" valign="top">&nbsp;</td>
          <td height="15" align="left" valign="top" class="12">
            <table width="100%" height="20" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td height="20" align="center">
                  <div class=padding>
                    <div id=middlebody>
                      <table width="50%" border="0" cellpadding="0" cellspacing="1">
                        <tr>
                          <td width="25%" height="20" align="right" bgcolor="#f3f3f3">户名</td>
                          <td width="2%" align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td width="73%" height="20" align="left" bgcolor="#f3f3f3">
                            <div align="left">{{name}}</div>
                          </td>
                        </tr>
                        <input type="hidden" value="gary" name="username"/>
                        <tr>
                          <td height="20" align="right" bgcolor="#f3f3f3">原始密码</td>
                          <td align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td height="20" align="left" bgcolor="#f3f3f3">
                            <div align="left">
                              <input id="temp1" type="password"
                                     ref="oldPassword"
                                     v-model="user.oldPassword"
                                     name="password"/>
                            </div>
                          </td>
                        </tr>
                        <tr>
                          <td height="20" align="right" bgcolor="#f3f3f3">新密码</td>
                          <td align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td height="20" align="left" bgcolor="#f3f3f3">
                            <div align="left">
                              <input id="temp2" type="password"
                                     ref="newPassword"
                                     v-model="user.newPassword"
                                     name="newpassword"/>
                            </div>
                          </td>
                        </tr>
                        <tr>
                          <td height="20" align="right" bgcolor="#f3f3f3">重复新密码</td>
                          <td align="right" bgcolor="#f3f3f3">&nbsp;</td>
                          <td height="20" align="left" bgcolor="#f3f3f3">
                            <div align="left">
                              <input id="temp3" type="password"
                                     ref="reNewPassword"
                                     v-model="user.reNewPassword"
                                     name="newdoublepassword"/>
                            </div>
                          </td>
                        </tr>
                        <tr>
                          <td height="20" colspan="2" align="middle" bgcolor="#f3f3f3">
                            &nbsp;
                          </td>
                          <td height="20" align="middle" bgcolor="#f3f3f3">
                            <div align="left">
                              <input type="button" @click="updatePwd()" value="确认更改"/>
                            </div>
                          </td>
                        </tr>
                      </table>
                    </div>
                  </div>
                </td>
              </tr>
            </table>
            <br/>
            <div class="table_wz"></div>
          </td>
        </tr>
      </table>
    </div>
  </div>
  <div id="container">
    <div id="footer">
      <p><a href="http://www.ascenttech.com.cn/" target="_blank">版权所有：北京亚思晟商务科技有限公司 &copy;2004-2008|京ICP备05005681</a>
      </p>
    </div>

  </div>
  </div>
</template>

<script>
export default {
name: "expertReworkPassword",
  data() {
    return {
      name: JSON.parse(sessionStorage.getItem("userInfo")).name || '',
      user: {
        uid: JSON.parse(sessionStorage.getItem("userInfo")).uid || '',
        oldPassword: '',
        newPassword: '',
        reNewPassword: '',
      },
    }
  },
  methods: {
    //注销
    logout() {
      sessionStorage.clear();
    },
    updatePwd() {
      var _this = this;
      if (this.user.oldPassword == "") {
        alert("旧密码格式不对");
        this.$refs['oldPassword'].focus();
      } else if (this.user.oldPassword === this.user.newPassword) {
        alert("新密码不能和旧密码相同");
        this.$refs['newPassword'].focus();
      } else if (this.user.newPassword !== this.user.reNewPassword) {
        alert("输入的新密码不一致");
        this.$refs['reNewPassword'].focus();
      } else {
        this.$axios({
          url: 'http://localhost:8080/api/expert/updatePwd',
          method: 'post',
          data: _this.user
        }).then((res) => {
          // console.log(res);
          if (res.data.code == 200) {
            alert('修改成功');
            this.$router.push('/declare/expert/index')
          } else {
            alert(res.data.msg);
          }
        })
      }
    }
  }
}
</script>

<style scoped>

</style>
